#include "options_menu.hpp"

#include <iostream>

OptionsMenu::OptionsMenu() {

}

OptionsMenu::~OptionsMenu() {

}

void OptionsMenu::init(Engine *engine) {

    selectedMenuItem = 0;

	/*sf::String gralaby;
	gralaby.SetFont(engine->getFont("data/fonts/BELIEVER.TTF"));
	gralaby.SetText("Gralaby");
	gralaby.SetPosition(sf::Vector2f(engine->window.GetWidth() / 2.f, 260));
	gralaby.SetCenter(sf::Vector2f(gralaby.GetRect().GetWidth() / 2.f, gralaby.GetRect().GetHeight() / 2.f));
	gralaby.SetColor(sf::Color(255, 255, 255, 255));
	gralaby.SetScale(sf::Vector2f(1.2f, 1.2f));*/

    sf::String back;
	back.SetFont(engine->getFont("data/fonts/BELIEVER.TTF"));
	back.SetText("Back");
	back.SetPosition(sf::Vector2f(engine->window.GetWidth() / 2.f, 360));
	back.SetCenter(sf::Vector2f(back.GetRect().GetWidth() / 2.f, back.GetRect().GetHeight() / 2.f));
	back.SetColor(sf::Color(255, 255, 255, 255));

	//menuItems.push_back(gralaby);
	menuItems.push_back(back);

	background.SetImage(engine->getImage("data/images/main-menu.png"));

	//themeMusic.Open("data/music/Goof.ogg"); //STFU
	//themeMusic.Play();
}

void OptionsMenu::cleanup() {
	//themeMusic.Stop();
	menuItems.clear();
}

void OptionsMenu::pause() {
	//themeMusic.Stop();
}

void OptionsMenu::resume() {
    //themeMusic.Play();
}

void OptionsMenu::processEvent(Engine *engine, PlayerEvent& event) {
	switch(event.type) {
		case PlayerEvent::MoveUp:
		{
			if(event.state)
				if(selectedMenuItem > 0) {
					menuItems[selectedMenuItem].SetScale(sf::Vector2f(1.f, 1.f));
					selectedMenuItem--;
					menuItems[selectedMenuItem].SetScale(sf::Vector2f(1.2f, 1.2f));
				}
			break;
		}
		case PlayerEvent::MoveDown:
		{
			if(event.state)
				if(selectedMenuItem < menuItems.size() - 1) {
					menuItems[selectedMenuItem].SetScale(sf::Vector2f(1.f, 1.f));
					selectedMenuItem++;
					menuItems[selectedMenuItem].SetScale(sf::Vector2f(1.2f, 1.2f));
				}
			break;
		}
		case PlayerEvent::Action1:
		{
			if(event.state) {
				switch(selectedMenuItem) {
				    case 0:
 						engine->popState();
						break;
					default:
						engine->popState();
						break;
				}
			}
			break;
		}
		case PlayerEvent::Quit:
		{
				if(event.state)
					engine->popState();
			break;
		}
		default:
			break;
	}
}

void OptionsMenu::update(Engine *engine) {
	/*if(gralaby.GetRect().Contains(engine->window.GetInput().GetMouseX(), engine->window.GetInput().GetMouseY())) gralaby.SetScale(sf::Vector2f(1.2f, 1.2f));
	else gralaby.SetScale(sf::Vector2f(1.0f, 1.0f));

	if(gunBuns.GetRect().Contains(engine->window.GetInput().GetMouseX(), engine->window.GetInput().GetMouseY())) gunBuns.SetScale(sf::Vector2f(1.2f, 1.2f));
	else gunBuns.SetScale(sf::Vector2f(1.0f, 1.0f));

	if(quit.GetRect().Contains(engine->window.GetInput().GetMouseX(), engine->window.GetInput().GetMouseY())) quit.SetScale(sf::Vector2f(1.2f, 1.2f));
	else quit.SetScale(sf::Vector2f(1.0f, 1.0f));*/
}

void OptionsMenu::draw(Engine *engine) {
	engine->window.Draw(background);

	for(std::vector<sf::String>::iterator iMenuItem = menuItems.begin(); iMenuItem != menuItems.end(); iMenuItem++)
		engine->window.Draw(*iMenuItem);
}
